{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 基本柱状图绘制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 垂直柱状图\n",
    "- 绘制方法：vbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method vbar in module bokeh.plotting.figure:\n",
      "\n",
      "vbar(x, width, top, bottom=0, *, fill_alpha=1.0, fill_color='gray', hatch_alpha=1.0, hatch_color='black', hatch_extra={}, hatch_pattern=None, hatch_scale=12.0, hatch_weight=1.0, line_alpha=1.0, line_cap='butt', line_color='black', line_dash=[], line_dash_offset=0, line_join='bevel', line_width=1, name=None, tags=[], **kwargs) method of bokeh.plotting.figure.Figure instance\n",
      "    Configure and add :class:`~bokeh.models.glyphs.VBar` glyphs to this Figure.\n",
      "    \n",
      "    Args:\n",
      "        x (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The x-coordinates of the centers of the vertical bars.\n",
      "    \n",
      "        width (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The widths of the vertical bars.\n",
      "    \n",
      "        top (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the top edges.\n",
      "    \n",
      "        bottom (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the bottom edges.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "    \n",
      "    Keyword args:\n",
      "        fill_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The fill alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        fill_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The fill color values for the vertical bars.\n",
      "    \n",
      "            (default: gray)\n",
      "    \n",
      "        hatch_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        hatch_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The hatch color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        hatch_extra (:class:`~bokeh.core.properties.Dict` ( :class:`~bokeh.core.properties.String` , :class:`~bokeh.core.properties.Instance` ( :class:`~bokeh.models.textures.Texture`  ) )):\n",
      "            The hatch extra values for the vertical bars.\n",
      "    \n",
      "            (default: {})\n",
      "    \n",
      "        hatch_pattern (:class:`~bokeh.core.properties.HatchPatternSpec` ):\n",
      "            The hatch pattern values for the vertical bars.\n",
      "    \n",
      "        hatch_scale (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch scale values for the vertical bars.\n",
      "    \n",
      "            (default: 12.0)\n",
      "    \n",
      "        hatch_weight (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch weight values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_cap (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineCap`  ), optional):\n",
      "            The line cap values for the vertical bars.\n",
      "    \n",
      "            (default: butt)\n",
      "    \n",
      "        line_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The line color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        line_dash (:class:`~bokeh.core.properties.DashPattern` ):\n",
      "            The line dash values for the vertical bars.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "        line_dash_offset (:class:`~bokeh.core.properties.Int` ):\n",
      "            The line dash offset values for the vertical bars.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "        line_join (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineJoin`  ), optional):\n",
      "            The line join values for the vertical bars.\n",
      "    \n",
      "            (default: bevel)\n",
      "    \n",
      "        line_width (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line width values for the vertical bars.\n",
      "    \n",
      "            (default: 1)\n",
      "    \n",
      "        name (:class:`~bokeh.core.properties.String` ):\n",
      "            An arbitrary, user-supplied name for this model.\n",
      "        \n",
      "            This name can be useful when querying the document to retrieve specific\n",
      "            Bokeh models.\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> plot.circle([1,2,3], [4,5,6], name=\"temp\")\n",
      "                >>> plot.select(name=\"temp\")\n",
      "                [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any names\n",
      "                that are provided, nor is the name used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "        tags (:class:`~bokeh.core.properties.List` ( :class:`~bokeh.core.properties.Any`  )):\n",
      "            An optional list of arbitrary, user-supplied values to attach to this\n",
      "            model.\n",
      "        \n",
      "            This data can be useful when querying the document to retrieve specific\n",
      "            Bokeh models:\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> r = plot.circle([1,2,3], [4,5,6])\n",
      "                >>> r.tags = [\"foo\", 10]\n",
      "                >>> plot.select(tags=['foo', 10])\n",
      "                [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]\n",
      "        \n",
      "            Or simply a convenient way to attach any necessary metadata to a model\n",
      "            that can be accessed by ``CustomJS`` callbacks, etc.\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any tags\n",
      "                that are provided, nor are the tags used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "    \n",
      "    \n",
      "    Other Parameters:\n",
      "        alpha (float, optional) :\n",
      "            An alias to set all alpha keyword arguments at once. (default: None)\n",
      "    \n",
      "            Alpha values must be between 0 (fully transparent) and 1 (fully opaque).\n",
      "    \n",
      "            Any explicitly set values for ``line_alpha``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "        color (Color, optional) :\n",
      "            An alias to set all color keyword arguments at once. (default: None)\n",
      "    \n",
      "            Acceptable values for colors are described in the `Specifying Colors`_\n",
      "            section of the User's Guide.\n",
      "    \n",
      "            Any explicitly set values for ``line_color``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "            .. _Specifying Colors: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#specifying-colors\n",
      "    \n",
      "        legend_field (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in the Browser`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed *in JavaScript*, at the time time the Bokeh\n",
      "            content is rendered in the browser. If the data is subsequently updated,\n",
      "            the legend will automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in the Browser: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-browser\n",
      "    \n",
      "        legend_group (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in Python`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed in Python, before the Bokeh output is sent to\n",
      "            a browser. If the date is subsequently updated, the legend will *not*\n",
      "            automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in Python: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-python\n",
      "    \n",
      "        legend_label (str, optional) :\n",
      "            Specify that the glyph should produce a single `Basic Legend Label`_ in\n",
      "            the legend. The legend entry is labeled with exactly the text supplied\n",
      "            here.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Basic Legend Label: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#basic-legend-label\n",
      "    \n",
      "        muted (bool, optionall) :\n",
      "            Whether the glyph should be rendered as muted (default: False)\n",
      "    \n",
      "            For this to be useful, an ``muted_glyph`` must be configured on the\n",
      "            returned ``GlyphRender``. This can be done by explicitly creating a\n",
      "            ``Glyph`` to use, or more simply by passing e.g. ``muted_color``, etc.\n",
      "            to this glyph function.\n",
      "    \n",
      "        name (str, optional) :\n",
      "            An optional user-supplied name to attach to the renderer (default: None)\n",
      "    \n",
      "            Bokeh does not use this value in any way, but it may be useful for\n",
      "            searching a Bokeh document to find a specific model.\n",
      "    \n",
      "        source (ColumnDataSource, optional) :\n",
      "            A user-supplied data source. (defatult: None)\n",
      "    \n",
      "            If not supplied, Bokeh will automatically construct an internal\n",
      "            ``ColumnDataSource`` with default column names from the coordinates and\n",
      "            other arguments that were passed-in as literal list or array values.\n",
      "    \n",
      "            If supplied, Bokeh will use the supplied data source to drive the glyph.\n",
      "            In this case, literal list or arrays may not be used for coordinates or\n",
      "            other arguments. Only singular fixed valued (e.g. ``x=10``) or column\n",
      "            names in the data souce (e.g. ``x=\"time\"``) are permitted.\n",
      "    \n",
      "        view (CDSView, optional) :\n",
      "            A view for filtering the data source. (default: None)\n",
      "    \n",
      "        visible (bool, optional) :\n",
      "            Whether the glyph should be rendered. (default: True)\n",
      "    \n",
      "        x_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping x-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        y_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping y-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        level (RenderLevel, optional) :\n",
      "            Specify the render level order for this glyph.\n",
      "    \n",
      "    \n",
      "    \n",
      "    It is also possible to set the color and alpha parameters of extra glyphs for\n",
      "    selection, nonselection, hover, or muted. To do so, add the relevane prefix to\n",
      "    any visual parameter. For example, pass ``nonselection_alpha`` to set the line\n",
      "    and fill alpha for nonselect, or ``hover_fill_alpha`` to set the fill alpha for\n",
      "    hover. See the `Glyphs`_ section od the User's Guide for full details.\n",
      "    \n",
      "    .. _Glyphs: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#glyphs\n",
      "    \n",
      "    Returns:\n",
      "        :class:`~bokeh.models.renderers.GlyphRenderer`\n",
      "    \n",
      "    \n",
      "    Examples:\n",
      "    \n",
      "        .. bokeh-plot::\n",
      "            :source-position: above\n",
      "    \n",
      "            from bokeh.plotting import figure, output_file, show\n",
      "    \n",
      "            plot = figure(plot_width=300, plot_height=300)\n",
      "            plot.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1,2,3], color=\"#CAB2D6\")\n",
      "    \n",
      "            show(plot)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(p.vbar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"7c8b7d58-68a7-4aa7-b0e5-0860e7b4e5ef\" data-root-id=\"1101\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"79c5e2b5-d27d-4023-8cb9-dec3df4ad48c\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1110\"}],\"center\":[{\"id\":\"1113\"},{\"id\":\"1117\"}],\"left\":[{\"id\":\"1114\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1135\"}],\"title\":{\"id\":\"1146\"},\"toolbar\":{\"id\":\"1125\"},\"x_range\":{\"id\":\"1102\"},\"x_scale\":{\"id\":\"1106\"},\"y_range\":{\"id\":\"1104\"},\"y_scale\":{\"id\":\"1108\"}},\"id\":\"1101\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1150\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1111\",\"type\":\"BasicTicker\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1146\",\"type\":\"Title\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1152\"},\"selection_policy\":{\"id\":\"1153\"}},\"id\":\"1132\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1102\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1110\"},\"ticker\":null},\"id\":\"1113\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1104\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1148\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"skyblue\"},\"line_color\":{\"value\":\"skyblue\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1133\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"formatter\":{\"id\":\"1148\"},\"ticker\":{\"id\":\"1111\"}},\"id\":\"1110\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1152\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1118\"},{\"id\":\"1119\"},{\"id\":\"1120\"},{\"id\":\"1121\"},{\"id\":\"1122\"},{\"id\":\"1123\"}]},\"id\":\"1125\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1115\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1132\"},\"glyph\":{\"id\":\"1133\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1134\"},\"selection_glyph\":null,\"view\":{\"id\":\"1136\"}},\"id\":\"1135\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"1114\"},\"dimension\":1,\"ticker\":null},\"id\":\"1117\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1119\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1124\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"1132\"}},\"id\":\"1136\",\"type\":\"CDSView\"},{\"attributes\":{\"overlay\":{\"id\":\"1124\"}},\"id\":\"1120\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1118\",\"type\":\"PanTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1150\"},\"ticker\":{\"id\":\"1115\"}},\"id\":\"1114\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"skyblue\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"skyblue\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1134\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1106\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1122\",\"type\":\"ResetTool\"}],\"root_ids\":[\"1101\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"79c5e2b5-d27d-4023-8cb9-dec3df4ad48c\",\"root_ids\":[\"1101\"],\"roots\":{\"1101\":\"7c8b7d58-68a7-4aa7-b0e5-0860e7b4e5ef\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1101"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画布 \n",
    "p=figure(plot_width=400,plot_height=400)\n",
    "#绘制柱状图\n",
    "p.vbar(x=[1,2,3],width=0.5,bottom=0,top=[1.2,2.5,3.7],color=\"skyblue\")\n",
    "#显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 水平柱状图\n",
    "- 绘制方法：hbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看参数\n",
    "??p.hbar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"cdce1a48-eb01-45a9-be40-4804f70992b2\" data-root-id=\"1209\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"5112744e-5ed1-4fee-b2a6-2b561041b092\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1220\"}],\"center\":[{\"id\":\"1223\"},{\"id\":\"1227\"}],\"left\":[{\"id\":\"1224\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1245\"}],\"title\":{\"id\":\"1210\"},\"toolbar\":{\"id\":\"1235\"},\"x_range\":{\"id\":\"1212\"},\"x_scale\":{\"id\":\"1216\"},\"y_range\":{\"id\":\"1214\"},\"y_scale\":{\"id\":\"1218\"}},\"id\":\"1209\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_color\":{\"value\":\"pink\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"pink\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1243\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"1229\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"pink\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"pink\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1244\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"1231\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1271\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1214\",\"type\":\"DataRange1d\"},{\"attributes\":{\"text\":\"\\u6c34\\u5e73\\u67f1\\u72b6\\u56feDemo\"},\"id\":\"1210\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1266\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1220\"},\"ticker\":null},\"id\":\"1223\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1212\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1224\"},\"dimension\":1,\"ticker\":null},\"id\":\"1227\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1221\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"1242\"},\"glyph\":{\"id\":\"1243\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1244\"},\"selection_glyph\":null,\"view\":{\"id\":\"1246\"}},\"id\":\"1245\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"overlay\":{\"id\":\"1234\"}},\"id\":\"1230\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1216\",\"type\":\"LinearScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1228\"},{\"id\":\"1229\"},{\"id\":\"1230\"},{\"id\":\"1231\"},{\"id\":\"1232\"},{\"id\":\"1233\"}]},\"id\":\"1235\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1234\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"formatter\":{\"id\":\"1268\"},\"ticker\":{\"id\":\"1225\"}},\"id\":\"1224\",\"type\":\"LinearAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"1266\"},\"ticker\":{\"id\":\"1221\"}},\"id\":\"1220\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1228\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1233\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1268\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1218\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1225\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1242\"}},\"id\":\"1246\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1270\",\"type\":\"Selection\"},{\"attributes\":{\"data\":{\"right\":[1.2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1270\"},\"selection_policy\":{\"id\":\"1271\"}},\"id\":\"1242\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1232\",\"type\":\"ResetTool\"}],\"root_ids\":[\"1209\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"5112744e-5ed1-4fee-b2a6-2b561041b092\",\"root_ids\":[\"1209\"],\"roots\":{\"1209\":\"cdce1a48-eb01-45a9-be40-4804f70992b2\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1209"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画布 \n",
    "p=figure(plot_width=400,plot_height=400,title=\"水平柱状图Demo\")\n",
    "p.hbar(y=[1, 2, 3], height=0.5, left=0,\n",
    "       right=[1.2, 2.5, 3.7], color=\"pink\")  \n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#数据准备\n",
    "from bokeh.models import ColumnDataSource\n",
    "fruits=['apples','pears','nectarines','plums','grapes','strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "\n",
    "source=ColumnDataSource(\n",
    "    data=dict(\n",
    "        x=fruits,\n",
    "        counts=counts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"9fa9a6ce-88f3-4660-b357-820bc2e6edd7\" data-root-id=\"1322\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"fd28140c-5bfb-4e42-b878-103a656b2b39\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1333\"}],\"center\":[{\"id\":\"1335\"},{\"id\":\"1339\"}],\"left\":[{\"id\":\"1336\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1359\"}],\"title\":{\"id\":\"1323\"},\"toolbar\":{\"id\":\"1348\"},\"x_range\":{\"id\":\"1325\"},\"x_scale\":{\"id\":\"1329\"},\"y_range\":{\"id\":\"1327\"},\"y_scale\":{\"id\":\"1331\"}},\"id\":\"1322\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"factors\":[\"apples\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"id\":\"1325\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1340\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1337\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1390\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1334\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1358\",\"type\":\"VBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1346\"}},\"id\":\"1342\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1357\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"1321\"},\"glyph\":{\"id\":\"1357\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1358\"},\"selection_glyph\":null,\"view\":{\"id\":\"1360\"}},\"id\":\"1359\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"1390\"},\"ticker\":{\"id\":\"1337\"}},\"id\":\"1336\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"1347\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1329\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"axis\":{\"id\":\"1333\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1335\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1331\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1388\"},\"ticker\":{\"id\":\"1334\"}},\"id\":\"1333\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1323\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1393\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"start\":0},\"id\":\"1327\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"apples\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"selected\":{\"id\":\"1392\"},\"selection_policy\":{\"id\":\"1393\"}},\"id\":\"1321\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"1336\"},\"dimension\":1,\"ticker\":null},\"id\":\"1339\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1388\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1340\"},{\"id\":\"1341\"},{\"id\":\"1342\"},{\"id\":\"1343\"},{\"id\":\"1344\"},{\"id\":\"1345\"},{\"id\":\"1347\"}]},\"id\":\"1348\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1343\",\"type\":\"SaveTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1346\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"1321\"}},\"id\":\"1360\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1341\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1345\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1344\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1392\",\"type\":\"Selection\"}],\"root_ids\":[\"1322\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"fd28140c-5bfb-4e42-b878-103a656b2b39\",\"root_ids\":[\"1322\"],\"roots\":{\"1322\":\"9fa9a6ce-88f3-4660-b357-820bc2e6edd7\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1322"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "TOOLTIPS=[(\"count\",\"@counts\")]\n",
    "p = figure(x_range=fruits, plot_height=350, title=\"Fruit Counts\",tooltips=TOOLTIPS)\n",
    "\n",
    "# 绘制\n",
    "p.vbar(x='x',top='counts', width=0.9,source=source)\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 课堂实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Star']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Visualization_tools']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.sources.ColumnDataSource\">ColumnDataSource</b>(</div><div style=\"display: table-cell;\">id&nbsp;=&nbsp;'1443', <span id=\"1445\" style=\"cursor: pointer;\">&hellip;)</span></div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">data&nbsp;=&nbsp;{'tools': ['matplotlib', 'bokeh', 'pyecharts', 'seaborn', 'plotly', 'ggplot2'], 'star': [9678, 11034, 5387, 6038, 4928, 3783], 'color': ['#3288bd', '#99d594', '#e6f598', '#fee08b', '#fc8d59', '#d53e4f']},</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name&nbsp;=&nbsp;None,</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">selected&nbsp;=&nbsp;Selection(id='1447', ...),</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">selection_policy&nbsp;=&nbsp;UnionRenderers(id='1446', ...),</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events&nbsp;=&nbsp;[],</div></div><div class=\"1444\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags&nbsp;=&nbsp;[])</div></div></div>\n",
       "<script>\n",
       "(function() {\n",
       "  var expanded = false;\n",
       "  var ellipsis = document.getElementById(\"1445\");\n",
       "  ellipsis.addEventListener(\"click\", function() {\n",
       "    var rows = document.getElementsByClassName(\"1444\");\n",
       "    for (var i = 0; i < rows.length; i++) {\n",
       "      var el = rows[i];\n",
       "      el.style.display = expanded ? \"none\" : \"table-row\";\n",
       "    }\n",
       "    ellipsis.innerHTML = expanded ? \"&hellip;)\" : \"&lsaquo;&lsaquo;&lsaquo;\";\n",
       "    expanded = !expanded;\n",
       "  });\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "ColumnDataSource(id='1443', ...)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source=ColumnDataSource(\n",
    "    data=dict(\n",
    "        tools=df['Visualization_tools'],\n",
    "        star=df['Star'],\n",
    "        color=Spectral6   #解决颜色板不可用问题，颜色也应对应存进source里\n",
    "    ))\n",
    "source"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"883c2091-852e-49db-b4b8-1bb38b8f47ec\" data-root-id=\"1448\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"b891e3eb-4ff0-4d0c-a24d-1b1167bc87bb\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1459\"}],\"center\":[{\"id\":\"1461\"},{\"id\":\"1465\"},{\"id\":\"1495\"}],\"left\":[{\"id\":\"1462\"}],\"renderers\":[{\"id\":\"1485\"}],\"title\":{\"id\":\"1449\"},\"toolbar\":{\"id\":\"1474\"},\"x_range\":{\"id\":\"1451\"},\"x_scale\":{\"id\":\"1455\"},\"y_range\":{\"id\":\"1453\"},\"y_scale\":{\"id\":\"1457\"}},\"id\":\"1448\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"label\":{\"field\":\"tools\"},\"renderers\":[{\"id\":\"1485\"}]},\"id\":\"1496\",\"type\":\"LegendItem\"},{\"attributes\":{\"formatter\":{\"id\":\"1488\"},\"ticker\":{\"id\":\"1460\"}},\"id\":\"1459\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1455\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1472\"}},\"id\":\"1468\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1470\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"1459\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1461\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1460\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1471\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1446\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"formatter\":{\"id\":\"1490\"},\"ticker\":{\"id\":\"1463\"}},\"id\":\"1462\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1490\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1443\"}},\"id\":\"1486\",\"type\":\"CDSView\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"\\u6570\\u503c\",\"@star\"],[\"\\u540d\\u79f0\",\"@tools\"]]},\"id\":\"1473\",\"type\":\"HoverTool\"},{\"attributes\":{\"items\":[{\"id\":\"1496\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"1495\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1447\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1466\"},{\"id\":\"1467\"},{\"id\":\"1468\"},{\"id\":\"1469\"},{\"id\":\"1470\"},{\"id\":\"1471\"},{\"id\":\"1473\"}]},\"id\":\"1474\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1472\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1483\",\"type\":\"VBar\"},{\"attributes\":{\"end\":14000,\"start\":0},\"id\":\"1453\",\"type\":\"DataRange1d\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1449\",\"type\":\"Title\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1484\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1488\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1451\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1469\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1467\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1443\"},\"glyph\":{\"id\":\"1483\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1484\"},\"selection_glyph\":null,\"view\":{\"id\":\"1486\"}},\"id\":\"1485\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1457\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1466\",\"type\":\"PanTool\"},{\"attributes\":{\"axis\":{\"id\":\"1462\"},\"dimension\":1,\"ticker\":null},\"id\":\"1465\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"star\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1447\"},\"selection_policy\":{\"id\":\"1446\"}},\"id\":\"1443\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1463\",\"type\":\"BasicTicker\"}],\"root_ids\":[\"1448\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"b891e3eb-4ff0-4d0c-a24d-1b1167bc87bb\",\"root_ids\":[\"1448\"],\"roots\":{\"1448\":\"883c2091-852e-49db-b4b8-1bb38b8f47ec\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1448"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "TOOLTIPS=[(\"数值\",\"@star\"),(\"名称\",\"@tools\")]\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github标星数量\",tooltips=TOOLTIPS)\n",
    "p.vbar(x='tools', top='star', width=0.8, color='color',source=source,legend=\"tools\") \n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.legend.location='top_center'\n",
    "p.legend.orientation=\"horizontal\"\n",
    "p.y_range.end=14000\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 课堂实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"b2513982-b205-4be5-be02-564ff5642f31\" data-root-id=\"1589\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"8c2ee4eb-54ba-4b8a-9de7-a96079b6a547\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1599\"}],\"center\":[{\"id\":\"1601\"},{\"id\":\"1605\"}],\"left\":[{\"id\":\"1602\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1623\"}],\"title\":{\"id\":\"1590\"},\"toolbar\":{\"id\":\"1613\"},\"x_range\":{\"id\":\"1588\"},\"x_scale\":{\"id\":\"1595\"},\"y_range\":{\"id\":\"1593\"},\"y_scale\":{\"id\":\"1597\"}},\"id\":\"1589\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1668\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"1588\",\"type\":\"FactorRange\"},{\"attributes\":{\"overlay\":{\"id\":\"1612\"}},\"id\":\"1608\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1595\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1611\",\"type\":\"HelpTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1606\"},{\"id\":\"1607\"},{\"id\":\"1608\"},{\"id\":\"1609\"},{\"id\":\"1610\"},{\"id\":\"1611\"}]},\"id\":\"1613\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"1602\"},\"dimension\":1,\"ticker\":null},\"id\":\"1605\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1606\",\"type\":\"PanTool\"},{\"attributes\":{\"start\":0},\"id\":\"1593\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1673\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1597\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1668\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"1600\"}},\"id\":\"1599\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"1670\"},\"ticker\":{\"id\":\"1603\"}},\"id\":\"1602\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1607\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1609\",\"type\":\"SaveTool\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"1672\"},\"selection_policy\":{\"id\":\"1673\"}},\"id\":\"1587\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1670\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"1590\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"1599\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1601\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1610\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1587\"},\"glyph\":{\"id\":\"1621\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1622\"},\"selection_glyph\":null,\"view\":{\"id\":\"1624\"}},\"id\":\"1623\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1672\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1600\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1612\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1603\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1587\"}},\"id\":\"1624\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1622\",\"type\":\"VBar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1621\",\"type\":\"VBar\"}],\"root_ids\":[\"1589\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"8c2ee4eb-54ba-4b8a-9de7-a96079b6a547\",\"root_ids\":[\"1589\"],\"roots\":{\"1589\":\"b2513982-b205-4be5-be02-564ff5642f31\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1589"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 课后实践\n",
    "star，commit,contribute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import ColumnDataSource,FactorRange\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9678, 11034, 5387, 6038, 4928, 3783]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "star_data=list(df['Star'])\n",
    "star_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[29503, 17673, 1321, 2316, 3370, 4286]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "commits_data=list(df['Commits'])\n",
    "commits_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[808, 357, 18, 98, 76, 184]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "contributors_data=list(df['Contributors'])\n",
    "contributors_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['matplotlib', 'bokeh', 'pyecharts', 'seaborn', 'plotly', 'ggplot2']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tools_data=list(df['Visualization_tools'])\n",
    "tools_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9678,\n",
       " 11034,\n",
       " 5387,\n",
       " 6038,\n",
       " 4928,\n",
       " 3783,\n",
       " 29503,\n",
       " 17673,\n",
       " 1321,\n",
       " 2316,\n",
       " 3370,\n",
       " 4286,\n",
       " 808,\n",
       " 357,\n",
       " 18,\n",
       " 98,\n",
       " 76,\n",
       " 184]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 合并列表数据，对应x轴坐标数量\n",
    "# 方法一\n",
    "# data={\n",
    "#         'star':star_data,\n",
    "#         'commits':commits_data,\n",
    "#         'contributors':contributors_data\n",
    "# }\n",
    "# data\n",
    "# counts =(data['star']+ data['commits']+ data['contributors'])\n",
    "\n",
    "#方法二\n",
    "counts=star_data+commits_data+contributors_data\n",
    "counts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 绘制画布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"18bd8394-2ab5-40e2-819d-759cf0be584f\" data-root-id=\"1725\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"449b5f86-e94d-493b-948f-4c3c39348c1d\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1735\"}],\"center\":[{\"id\":\"1737\"},{\"id\":\"1741\"},{\"id\":\"1771\"}],\"left\":[{\"id\":\"1738\"}],\"plot_height\":500,\"renderers\":[{\"id\":\"1761\"}],\"title\":{\"id\":\"1726\"},\"toolbar\":{\"id\":\"1750\"},\"x_range\":{\"id\":\"1724\"},\"x_scale\":{\"id\":\"1731\"},\"y_range\":{\"id\":\"1729\"},\"y_scale\":{\"id\":\"1733\"}},\"id\":\"1725\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_color\":{\"value\":\"pink\"},\"line_color\":{\"value\":\"pink\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1759\",\"type\":\"VBar\"},{\"attributes\":{\"items\":[{\"id\":\"1772\"}]},\"id\":\"1771\",\"type\":\"Legend\"},{\"attributes\":{\"source\":{\"id\":\"1723\"}},\"id\":\"1762\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1733\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1764\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"1736\"}},\"id\":\"1735\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1766\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1745\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1764\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"start\":0},\"id\":\"1729\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"1766\"},\"ticker\":{\"id\":\"1739\"}},\"id\":\"1738\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"pink\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"pink\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1760\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1769\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1746\",\"type\":\"ResetTool\"},{\"attributes\":{\"label\":{\"value\":\"tools\"},\"renderers\":[{\"id\":\"1761\"}]},\"id\":\"1772\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1743\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1723\"},\"glyph\":{\"id\":\"1759\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1760\"},\"selection_glyph\":null,\"view\":{\"id\":\"1762\"}},\"id\":\"1761\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1739\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1735\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1737\",\"type\":\"Grid\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1748\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1736\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributors\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributors\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributors\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributors\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributors\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributors\"]],\"range_padding\":0.1},\"id\":\"1724\",\"type\":\"FactorRange\"},{\"attributes\":{\"data\":{\"counts\":[9678,11034,5387,6038,4928,3783,29503,17673,1321,2316,3370,4286,808,357,18,98,76,184],\"x\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributors\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributors\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributors\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributors\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributors\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributors\"]]},\"selected\":{\"id\":\"1768\"},\"selection_policy\":{\"id\":\"1769\"}},\"id\":\"1723\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"\\u6570\\u91cf\",\"@counts\"]]},\"id\":\"1749\",\"type\":\"HoverTool\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u3001\\u63d0\\u4ea4\\u3001\\u8d21\\u732e\\u8005\\u6570\\u91cf\"},\"id\":\"1726\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1747\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1748\"}},\"id\":\"1744\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1742\"},{\"id\":\"1743\"},{\"id\":\"1744\"},{\"id\":\"1745\"},{\"id\":\"1746\"},{\"id\":\"1747\"},{\"id\":\"1749\"}]},\"id\":\"1750\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1731\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1768\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"1738\"},\"dimension\":1,\"ticker\":null},\"id\":\"1741\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1742\",\"type\":\"PanTool\"}],\"root_ids\":[\"1725\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"449b5f86-e94d-493b-948f-4c3c39348c1d\",\"root_ids\":[\"1725\"],\"roots\":{\"1725\":\"18bd8394-2ab5-40e2-819d-759cf0be584f\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1725"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#不需要分开写不同类别的数据，只需要将数据与x轴坐标名称一一对应即可\n",
    "TOOLTIPS=[(\"数量\",\"@counts\")]\n",
    "tools = tools_data\n",
    "tpyes = ['star', 'commits', 'contributors']\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (tool, tpye) for tool in tools for tpye in tpyes ]\n",
    "source=ColumnDataSource(\n",
    "    data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=500, title=\"2019年7月常见可视化工具Github标星、提交、贡献者数量\",tooltips=TOOLTIPS)\n",
    "# 柱状图\n",
    "p.vbar(x='x',top='counts',width=0.9, source=source,legend=\"tools\",color=\"pink\")\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "303.825px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
